package org.dormi.learn.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 简单打印当前 类名.方法名
 *
 * @author : dormi330
 * @version : 1.0
 */
public class TrackingUtils {

    private static final Logger log = LoggerFactory.getLogger(TrackingUtils.class);

    public static String getCurrentClassAndMethodNames() {
        final StackTraceElement e = Thread.currentThread().getStackTrace()[2];
        final String s = e.getClassName();
        return s.substring(s.lastIndexOf('.') + 1, s.length()) + "." + e.getMethodName();
    }


    public static void debugTrace() {
        if (!log.isDebugEnabled()) {
            return;
        }
        final StackTraceElement e = Thread.currentThread().getStackTrace()[2];
        final String s = e.getClassName();
        String classAndMethod = s.substring(s.lastIndexOf('.') + 1, s.length()) + "." + e.getMethodName();
        log.debug(classAndMethod);
    }

    public static void debugTrace(boolean force) {
        if (!log.isDebugEnabled() && !force) {
            return;
        }
        final StackTraceElement e = Thread.currentThread().getStackTrace()[2];
        final String s = e.getClassName();
        String classAndMethod = s.substring(s.lastIndexOf('.') + 1, s.length()) + "." + e.getMethodName();
        log.debug(classAndMethod);
    }
}
